package routes;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import db.Blog;
import db.Routes;
import db.SessionFactoryUtil;

public class RoutesHome {
	
	/**
	 * Pobranie eventow
	 * @return List articles
	 */
	public static List getRoutes(int idU) {
		Session session = SessionFactoryUtil.getSession();
		
		Query query = session.createQuery("from Routes where idU = :idU");
		query.setParameter("idU", idU);
		List list = query.list();
		if(list.isEmpty()) {
			return null;
		} else {
			return list;			
		}	
	}



	/**
	 * Usuniecie eventu
	 */
	
	public static int removeRoute(int idR) {
		Session session = SessionFactoryUtil.getSession();
		
		Query query = session.createQuery("delete from Routes where idR = :idR");
		query.setParameter("idR", idR);
		int result = query.executeUpdate();
		return result;
	}
	
	
	/**
	 * Pobranie artykulu
	 */
	
	public static Routes getRoute(int idR) {
		Session session = SessionFactoryUtil.getSession();
		
		Query query = session.createQuery("from Routes where idR = :idR");
		query.setParameter("idR", idR);
		List list = query.list();
		if(list.isEmpty()) {
			return null;
		} else {
			return (Routes) list.get(0);			
		}	
	}

}
